import Vue from "vue";
import VueI18n from "vue-i18n";

Vue.use(VueI18n);

export default ({ app, store }) => {
  app.i18n = new VueI18n({
    locale: store.state.locale,
    fallbackLocale: "VI", // 默认为越南语
    messages: {
      ZH: require("@/assets/i18n/zh.json"),
      EN: require("@/assets/i18n/en.json"),
      VI: require("@/assets/i18n/vi.json")
    }
  });

  app.i18n.path = link => {
    // 如果是默认语言，就省略
    if (app.i18n.locale === app.i18n.fallbackLocale) {
      return `/${link}`;
    }
    return `/${app.i18n.locale}/${link}`;
  };
};
